* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file runs additional regressions for export market outcomes.

* Setup
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_dom_product_cn8plus.dta", clear

* Drop if either acquirer or target has no products before (because guaranteed to be no overlap)
drop if nprod_before==0 | nprodT==0

* Use shares besides ranks
egen sumvrdA_before = sum(vrdA_before), by(cvrnrA aar)
gen shareA_before = vrdA_before/sumvrdA_before
gen shareA_before_overlap = shareA_before if vrdA_before!=. & vrdT_before!=.

egen sumvrdT_before = sum(vrdT_before), by(cvrnrA aar)
gen shareT_before = vrdT_before/sumvrdT_before
gen shareT_before_overlap = shareT_before if vrdA_before!=. & vrdT_before!=.

gen shareAT_before = shareA_before*shareT_before
gen shareA_beforesq = shareA_before^2
gen shareT_beforesq = shareT_before^2

collapse (sum) shareAT_before shareA_beforesq shareT_beforesq, by(cvrnrA aar)

*Bloom et al. 2013 measure
gen sicij = shareAT_before/shareA_beforesq^0.5/shareT_beforesq^0.5
sum sicij, d
local med = r(p50)

tempfile tempfile1
save `tempfile1.dta', replace

* Main data
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\regression_data_export.dta", clear

merge m:1 cvrnrA aar using `tempfile1.dta', keepusing(sicij) keep(match master) nogen
egen msicij = mean(sicij), by(cvrnrA)

* Figure A.17(d), (e), (f)
foreach x in lnnmark lnnprod {
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & msicij>`med' & msicij!=.) | acquirer==0) & _mergedist==3, fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & msicij<=`med') | acquirer==0) & _mergedist==3, fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes 
}

foreach x in lnnprodpermark{
did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & max_merge==3 & msicij>`med' & msicij!=.) | acquirer==0) & _mergedist==3, fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes 

did_imputation `x' group_cvrnr aarA aar3 if minemployee_cvrnr>=10 & ((acquirer==1 & max_merge==3 & msicij<=`med') | acquirer==0) & _mergedist==3, fe(group_cvrnr aarA) hor(0/2) pretrend(4) tol(0.0001) maxit(250) autosample cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_figureA17.txt", bdec(4) sdec(4) nocons nonotes 
}